package com.owen.he.jee.utils.excel;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
/**
 * 实体类，对Xml节点的属性和值进行封装
 */
public class XmlNode {
	//节点名字
	private String name = null; 
	//节点值
	private String value = null;
	//属性列表
	private HashMap <String,String> attributeMap = new  HashMap<String,String>();
	//下级节点
	private ArrayList <XmlNode> subNode = new ArrayList<XmlNode>();
	
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	
	public String getValue() {
		return value;
	}
	public void setValue(String value) {
		this.value = value;
	}
	
	public String getAttribute(String key) {
		return attributeMap.get(key);
	}
	public void setAttribute(String key,String value) {
		attributeMap.put(key, value);
	}
	
	public List <String> getAttributesName(){
		List <String> list = new ArrayList<String>();
		Iterator it = attributeMap.keySet().iterator();
		while(it.hasNext()){
			String str = it.next().toString();
			list.add(str);
		}
		return list;
	}
	/**
	 * 获取所有下级节点
	 * @return
	 */
	public ArrayList <XmlNode> getSubNode(){
		return subNode;
	}
	
	/**
	 * 根据节点名获取下级节点
	 * @param name
	 * @return
	 */
	public ArrayList <XmlNode> getSubNode(String name){
		ArrayList <XmlNode> selectList = new ArrayList<XmlNode>();
		for(XmlNode xmlNode:subNode){
			if(xmlNode.getName().equals(name)){
				selectList.add(xmlNode);
			}
		}
		return selectList;
	}
	
	public void setSubNode(XmlNode xmlNode){
		subNode.add(xmlNode);
	}
}
